package com.ruoyi.project.gxgw_modules.found.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.gxgw_modules.found.domain.Found;
import com.ruoyi.project.gxgw_modules.found.service.IFoundService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 宠物招领记录 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-01-21
 */
@Controller
@RequestMapping("/gxgw_modules/found")
public class FoundController extends BaseController
{
    private String prefix = "gxgw_modules/found";
	
	@Autowired
	private IFoundService foundService;
	
	@RequiresPermissions("gxgw_modules:found:view")
	@GetMapping()
	public String found()
	{
	    return prefix + "/found";
	}
	
	/**
	 * 查询宠物招领记录列表
	 */
	@RequiresPermissions("gxgw_modules:found:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Found found)
	{
		startPage();
        List<Found> list = foundService.selectFoundList(found);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出宠物招领记录列表
	 */
	@RequiresPermissions("gxgw_modules:found:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Found found)
    {
    	List<Found> list = foundService.selectFoundList(found);
        ExcelUtil<Found> util = new ExcelUtil<Found>(Found.class);
        return util.exportExcel(list, "found");
    }
	
	/**
	 * 新增宠物招领记录
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存宠物招领记录
	 */
	@RequiresPermissions("gxgw_modules:found:add")
	@Log(title = "宠物招领记录", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Found found)
	{		
		return toAjax(foundService.insertFound(found));
	}

	/**
	 * 修改宠物招领记录
	 */
	@GetMapping("/edit/{foundId}")
	public String edit(@PathVariable("foundId") Integer foundId, ModelMap mmap)
	{
		Found found = foundService.selectFoundById(foundId);
		mmap.put("found", found);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存宠物招领记录
	 */
	@RequiresPermissions("gxgw_modules:found:edit")
	@Log(title = "宠物招领记录", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Found found)
	{		
		return toAjax(foundService.updateFound(found));
	}
	
	/**
	 * 删除宠物招领记录
	 */
	@RequiresPermissions("gxgw_modules:found:remove")
	@Log(title = "宠物招领记录", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(foundService.deleteFoundByIds(ids));
	}
	
}
